home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Tools / TASM V5 / TASMDOC.PAK / TLIB.TXT < prev    next >
Text File  |  1996-02-21  |  19KB  |  454 lines

  1. /*************************************************************************/
  2.                                  TLIB.TXT
  3.                               TURBO ASSEMBLER
  4.  
  5. This file contains details on using TLIB with TASM.
  6.  
  7. --------------------------------------------------------------------
  8.                         TABLE OF CONTENTS
  9.                         - - - - - - - - -
  10.    Using IMPLIB: The import librarian
  11.    Using IMPDEF: The module-definition file manager
  12.       Classes in a DLL
  13.       Functions in a DLL
  14.    Using TLIB: the Turbo Librarian
  15.       Why use object module libraries?
  16.       The TLIB command line
  17.          Using response files
  18.          Using case-sensitive symbols: The /C option
  19.          Creating an extended dictionary: The /E option
  20.          Setting the page size: The /P option
  21.          Removing comment records: The /0 option
  22.          The operation list
  23.       Examples
  24.  
  25. --------------------------------------------------------------------
  26.  
  27. This chapter describes several tools that let you work with library
  28. files.
  29.  
  30.   o  IMPLIB creates import libraries, and IMPDEF creates module
  31.      definition files (.DEF files). Import libraries and module
  32.      definition files provide information to the linker about
  33.      functions imported from dynamic-link libraries (DLLs).
  34.  
  35.   o  TLIB is a utility that manages libraries of individual .OBJ
  36.      (object module) files. A library is a convenient tool for
  37.      dealing with a collection of object modules as a single unit.
  38.  
  39.  
  40. Using IMPLIB: The import librarian
  41. ==================================
  42. The IMPLIB utility creates import libraries. IMPLIB takes as input
  43. DLLs, module definition files, or both, and produces an import library
  44. as output. When you add a DLL as a target, the project manager
  45. compiles and links the DLL's dependent files to create the .DLL file,
  46. then runs IMPLIB to create a .LIB file.
  47.  
  48. Import libraries contain records. Each record contains the name of a
  49. DLL, and specifies where in the DLL the imported functions reside.
  50. These records are bound to the application by TLINK or the IDE linker,
  51. and provide Windows with the information necessary to resolve DLL
  52. function calls. An import library can be substituted for part or all
  53. of the IMPORTS section of a module definition file.
  54.  
  55. If you've created a Windows application, you've already used at least
  56. one import library, IMPORT.LIB, the import library for the standard
  57. Windows DLLs.
  58.  
  59. An import library lists some or all of the exported functions for one
  60. or more DLLs. IMPLIB creates an import library directly from DLLs or
  61. from module definition files for DLLs (or a combination of the two).
  62.  
  63. To create an import library for a DLL, type
  64.  
  65.     IMPLIB Options LibName [DefFiles...|DLLs...]
  66.  
  67. where 'Options' is an optional list of one or more IMPLIB options,
  68. 'LibName' is the name for the new import library, 'DefFiles' is a list
  69. of one or more existing module definition files for one or more DLLs,
  70. and 'DLLs' is a list of one or more existing DLLs. You must specify at
  71. least one DLL or module definition file.
  72.  
  73. A DLL can also have an extension of .EXE or .DRV, not just .DLL.
  74.  
  75. Options must be lowercase and preceded by either a hyphen or a slash.
  76.  
  77. Option        Description
  78. ------        -----------
  79. -c        Accepts case-sensitive symbols. If you have two symbols
  80.         that differ only in case (like MYSYM and mysym) and you
  81.         don't use -c, IMPLIB uses the first symbol and treats
  82.         the second one as a duplicate.
  83.  
  84. -i        Tells IMPLIB to ignore WEP, the Windows exit procedure
  85.         required to end a DLL. Use this option if you are
  86.         specifying more than one DLL on the IMPLIB command line.
  87.  
  88. -w        No warnings.
  89.  
  90.  
  91. Using IMPDEF: The module-definition file manager
  92. ================================================
  93. IMPDEF takes as input a DLL name, and produces as output a module
  94. definition file with an export section containing the names of
  95. functions exported by the DLL. The syntax is
  96.  
  97.     IMPDEF DestName.DEF SourceName.DLL
  98.  
  99. This creates a module definition file named 'DestName'.DEF from the
  100. file 'SourceName'.DLL. The resulting module definition file would look
  101. something like this:
  102.  
  103.     LIBRARY     FileName
  104.  
  105.     DESCRIPTION 'Description'
  106.  
  107.     EXPORTS
  108.         ExportFuncName      @Ordinal
  109.         ExportFuncName      @Ordinal
  110.  
  111. where 'FileName' is the DLL's root file name, 'Description' is the
  112. value of the DESCRIPTION statement if the DLL was previously linked
  113. with a module definition file that included a DESCRIPTION statement,
  114. 'ExportFuncName' names an exported function, and 'Ordinal' is that
  115. function's ordinal value (an integer).
  116.  
  117.  
  118. Classes in a DLL
  119. ----------------
  120. IMPDEF is useful for a DLL that uses C++ classes. If you use the
  121. _export keyword when defining a class, all of the non-inline member
  122. functions and static data members for that class are exported. It's
  123. easier to let IMPDEF make a module definition file for you because it
  124. lists all the exported functions, and automatically includes the
  125. member functions and static data members.
  126.  
  127. Since the names of these functions are mangled, it would be tedious to
  128. list them all in the EXPORTS section of a module definition file
  129. simply to create an import library from the module definition file. If
  130. you use IMPDEF to create the module definition file, it includes the
  131. ordinal value for each exported function. If the exported name is
  132. mangled, IMPDEF also includes that function's unmangled, original name
  133. as a comment following the function entry. So, for instance, the
  134. module definition file created by IMPDEF for a DLL that used C++
  135. classes would look something like this:
  136.  
  137.     LIBRARY     FileName
  138.  
  139.     DESCRIPTION 'Description'
  140.  
  141.     EXPORTS
  142.         MangledExportFuncName  @Ordinal ; ExportFuncName
  143.         MangledExportFuncName  @Ordinal ; ExportFuncName
  144.  
  145. where 'FileName' is the DLL's root file name, 'Description' is the
  146. value of the DESCRIPTION statement if the DLL was previously linked
  147. with a module definition file that included a DESCRIPTION statement,
  148. 'MangledExportFuncName' provides the mangled name, 'Ordinal' is that
  149. function's ordinal value (an integer), and 'ExportFuncName' gives the
  150. function's original name.
  151.  
  152.  
  153. Functions in a DLL
  154. ------------------
  155. IMPDEF creates an editable source file that lists all the exported
  156. functions in the DLL. You can edit this .DEF file to contain only
  157. those functions that you want to make available to a particular
  158. application, then run IMPLIB on the edited .DEF file. This results in
  159. an import library that contains import information for a specific
  160. subset of a DLL's export functions.
  161.  
  162. Suppose you're distributing a DLL that provides functions to be used
  163. by several applications. Every export function in the DLL is defined
  164. with _export. Now, if all the applications used all the DLL's exports,
  165. then you could use IMPLIB to make one import library for the DLL. You
  166. could deliver that import library with the DLL, and it would provide
  167. import information for all of the DLL's exports. The import library
  168. could be linked to any application, thus eliminating the need for the
  169. particular application to list every DLL function it uses in the
  170. IMPORTS section of its module definition file.
  171.  
  172. But let's say you want to give only a few of the DLL's exports to a
  173. particular application. Ideally, you want a customized import library
  174. to be linked to that application--an import library that provides
  175. import information only for the subset of functions that the
  176. application uses. All of the other export functions in the DLL are
  177. hidden to that client application.
  178.  
  179. To create an import library that satisfies these conditions, run
  180. IMPDEF on the compiled and linked DLL. IMPDEF produces a module
  181. definition file that contains an EXPORT section listing all of the
  182. DLL's export functions. You can edit that module definition file,
  183. remove the EXPORTS section entries for those functions you don't want
  184. in the customized import library, and then run IMPLIB on the module
  185. definition file. The result is an import library that contains import
  186. information for only those export functions listed in the EXPORTS
  187. section of the module definition file.
  188.  
  189.  
  190. Using TLIB: the Turbo Librarian
  191. ===============================
  192. When it modifies an existing library, TLIB always creates a copy of
  193. the original library with a .BAK extension.
  194.  
  195. You can use TLIB to build and modify your own libraries, libraries
  196. furnished by other programmers, or commercial libraries you've
  197. purchased. You can also use TLIB to:
  198.  
  199.   o  Create a new library from a group of object modules.
  200.  
  201.   o  Add object modules or other libraries to an existing library.
  202.  
  203.   o  Remove object modules from an existing library.
  204.  
  205.   o  Replace object modules from an existing library.
  206.  
  207.   o  Extract object modules from an existing library.
  208.  
  209.   o  List the contents of a new or existing library.
  210.  
  211.  
  212. Why use object module libraries?
  213. --------------------------------
  214. When you program, you often create a collection of useful functions.
  215. With modular programming, you are likely to split those functions into
  216. many separately compiled source files. Any particular program might
  217. use only a subset of functions from the entire collection.
  218.  
  219. An object module library manages a collection of functions and
  220. classes. When you link your program with a library, the linker scans
  221. the library and automatically selects only those modules needed for
  222. the current program.
  223.  
  224.  
  225. The TLIB command line
  226. ---------------------
  227. The TLIB command line takes the following general form, where items
  228. listed in square brackets are optional:
  229.  
  230.     tlib [@respfile] [option] libname [operations] [, listfile]
  231.  
  232.  
  233. Option        Description
  234. ------        -----------
  235. @respfile    The path and name of the response file you want to
  236.         include. You can specify more than one response file.
  237.  
  238. libname     The DOS path name of the library you want to create or
  239.         manage. Every TLIB command must be given a libname.
  240.         Wildcards are not allowed. TLIB assumes an extension
  241.         of .LIB if none is given. (It's best to use only the
  242.         .LIB extension.) NOTE: If the named library does not
  243.         exist and there are 'add' operations, TLIB creates the
  244.         library.
  245.  
  246. /C        The case-sensitive flag. This option is not normally
  247.         used.
  248.  
  249. /E        Creates Extended Dictionary.
  250.  
  251. /Psize        Sets the library page size to 'size'.
  252.  
  253. /0        Removes comment records from the library.
  254.  
  255. operations    The list of operations TLIB performs. Operations can
  256.         appear in any order. If you only want to examine the
  257.         contents of the library, don't give any operations.
  258.  
  259. listfile    The name of the file that lists library contents. It
  260.         must be preceded by a comma. No listing is produced if
  261.         you don't give a file name. The listing is an
  262.         alphabetical list of each module. The entry for each
  263.         module contains an alphabetical list of each public
  264.         symbol defined in that module. The default extension
  265.         for the 'listfile' is .LST. You can direct the listing
  266.         to the screen by using the 'listfile' name CON, or to
  267.         the printer by using the name PRN.
  268.  
  269.  
  270. Using response files
  271. - - - - - - - - - - -
  272. When you use a large number of operations, or if you find yourself
  273. repeating certain sets of operations over and over, you will probably
  274. want to use response files. A response file is an ASCII text file that
  275. contains all or part of a TLIB command. Using response files, you can
  276. build TLIB commands larger than would fit on one command line.
  277. Response files can:
  278.  
  279.   o  Contain more than one line of text; use the ampersand
  280.      character (&) at the end of a line to indicate that
  281.      another line follows.
  282.  
  283.   o  Include a partial list of commands. You can combine
  284.      options from the command line with options in a response file.
  285.  
  286.   o  Be used with other response files in a single TLIB command line.
  287.  
  288.  
  289. Using case-sensitive symbols: The /C option
  290. - - - - - - - - - - - - - - - - - - - - - -
  291. TLIB maintains a dictionary of all public symbols defined in the
  292. modules of the library. When you add a module to a library, its symbol
  293. must be unique. If you try to add a module to the library that
  294. duplicates a symbol, TLIB displays an error message and doesn't add
  295. the module.
  296.  
  297. NOTE: Don't use /C if you plan to use the library with other linkers
  298. or let other people use the library.
  299.  
  300. Because some linkers aren't case-sensitive, TLIB rejects symbols that
  301. differ only in case (for example, the symbols 'lookup' and 'LOOKUP'
  302. are treated as duplicates). TLINK, however, can distinguish case, so
  303. if you use your library only with TLINK, you can use the TLIB /C
  304. option to add a module to a library that includes symbols differing
  305. only in case.
  306.  
  307.  
  308. Creating an extended dictionary: The /E option
  309. - - - - - - - - - - - - - - - -  - - - - - - - -
  310. To increase the linker's capacity for large links, you can use TLIB to
  311. create an extended dictionary and append it to the library file. This
  312. dictionary contains, in a compact form, information that is not
  313. included in the standard library dictionary and that lets the linker
  314. (TLINK) preprocess library files so that any unnecessary modules are
  315. not preprocessed.
  316.  
  317. To create an extended dictionary for a library that you're modifying,
  318. use the /E option when you start TLIB to add, remove, or replace
  319. modules in the library. You can also use the /E option to create an
  320. extended dictionary for an existing library that you don't want to
  321. modify. For example, if you type "TLIB /E mylib" the linker appends an
  322. extended dictionary to the specified library.
  323.  
  324. If you use /E to add a library module containing a C++ class with a
  325. virtual function, you'll get the error message "Library contains
  326. COMDEF records--extended dictionary not created".
  327.  
  328.  
  329. Setting the page size: The /P option
  330. - - - - - - - - - - - - - - - - -  -
  331. Every DOS library file contains a dictionary that appears at the end
  332. of the .LIB file, following all of the object modules. For each module
  333. in the library, the dictionary contains a 16-bit address of that
  334. particular module within the .LIB file; this address is given in terms
  335. of the library page size (it defaults to 16 bytes).
  336.  
  337. The library page size determines the maximum combined size of all
  338. object modules in the library, which cannot exceed 65,536 pages. The
  339. default (and minimum) page size of 16 bytes allows a library of about
  340. 1 MB in size. To create a larger library, use the /P option to
  341. increase the page size. The page size must be a power of 2, and it
  342. cannot be smaller than 16 or larger than 32,768.
  343.  
  344. All modules in the library must start on a page boundary. For example,
  345. in a library with a page size of 32 (the lowest possible page size
  346. higher than the default 16), an average of 16 bytes is lost per object
  347. module in padding. If you attempt to create a library that is too
  348. large for the given page size, TLIB issues an error message and
  349. suggests that you use /P with the next available higher page size.
  350.  
  351.  
  352. Removing comment records: The /0 option
  353. - - - - - - - - - - - - - - - - - - - -
  354. Use the /0 option to remove comment records, which reduces the size of
  355. a library. For example, you might have debugging or browsing
  356. information in a library, but you no longer need to use that
  357. information; the /0 option removes that information.
  358.  
  359.  
  360. The operation list
  361. - - - - - - - - - -
  362. The operation list describes what actions you want TLIB to do. It
  363. consists of a sequence of operations given one after the other. Each
  364. operation consists of a one- or two-character action symbol followed
  365. by a file or module name. You can put whitespace around either the
  366. action symbol or the file or module name but not in the middle of a
  367. two-character action or in a name.
  368.  
  369. You can put as many operations as you like on the command line, up to
  370. 126 characters. The order of the operations is not important. TLIB
  371. always applies the operations in a specific order:
  372.  
  373.  1) All extract operations are done first.
  374.  
  375.  2) All remove operations are done next.
  376.  
  377.  3) All add operations are done last.
  378.  
  379. TLIB finds the name of a module by stripping any drive, path, and
  380. extension information from the given file name. TLIB always assumes
  381. reasonable defaults. For example, to add a module that has an .OBJ
  382. extension from the current directory, you need to supply only the
  383. module name, not the path and .OBJ extension.
  384.  
  385. TLIB recognizes three action symbols (-, +, *), which you can use
  386. singly or combined in pairs for a total of five distinct operations.
  387. The action symbols and what they do are listed here:
  388.  
  389. Symbol    Name        Description
  390. ------    ----        -----------
  391. +    Add        TLIB adds the named file to the library. If
  392.             the file has no extension, TLIB assumes an
  393.             extension of .OBJ. If the file is itself a
  394.             library (with a .LIB extension), then the
  395.             operation adds all of the modules in the named
  396.             library to the target library. If a module
  397.             being added already exists, TLIB displays a
  398.             message and does not add the new module.
  399.  
  400. -    Remove        TLIB removes the named module from the
  401.             library. If the module does not exist in the
  402.             library, TLIB displays a message. A remove
  403.             operation needs only a module name. TLIB lets
  404.             you enter a full path name with drive and
  405.             extension included, but ignores everything
  406.             except the module name.
  407.  
  408. *    Extract        TLIB creates the named file by copying the
  409.             corresponding module from the library to the
  410.             file. If the module does not exist, TLIB
  411.             displays a message and does not create a file.
  412.             If the named file already exists, it is
  413.             overwritten.
  414.  
  415. -*    Extract &    TLIB copies the named module to the
  416.             corresponding file name and then removes it
  417.             from the library.
  418.  
  419. -+    Replace        TLIB replaces the named module with the
  420.             corresponding file.
  421.  
  422.  
  423. Examples
  424. --------
  425. These examples demonstrate some of the things you can do with TLIB:
  426.  
  427.   o  To create a library named MYLIB.LIB with modules X.OBJ,
  428.      Y.OBJ, and Z.OBJ, type "tlib mylib +x +y +z".
  429.  
  430.   o  To create a library named MYLIB.LIB and get a listing
  431.      in MYLIB.LST too, type "tlib mylib +x +y +z, mylib.lst".
  432.  
  433.   o  To replace module X.OBJ with a new copy, add A.OBJ and
  434.      delete Z.OBJ from MYLIB.LIB, type "tlib mylib -+x +a -z".
  435.  
  436.   o  To create a new library (ALPHA) with modules A.OBJ,
  437.      B.OBJ...G.OBJ using a response file:
  438.  
  439.      First create a text file, ALPHA.RSP, with
  440.  
  441.         @^+a.obj +b.obj +c.obj &
  442.            +d.obj +e.obj +f.obj &
  443.            +g.obj
  444.  
  445.      Then use the TLIB command, which produces a listing file named
  446.      ALPHA.LST: "tlib alpha @alpha.rsp, alpha.lst".
  447.  
  448. NOTE: You can't directly rename modules in a library. To rename a
  449. module, extract and remove it, rename the file just created, then add
  450. it back into the library.
  451.  
  452. /**************************** END OF FILE ********************************/
  453.  
  454.